package com.itao;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.style.AbstractCellStyleStrategy;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Workbook;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author sjt
 * @Date 2025/4/22 15:54
 */
public class ExcelHead {

    public static void main(String[] args) {


        String fileName = "C:\\Users\\sjt\\Desktop\\1.xlsx";
        // 方案1
        EasyExcel.write(fileName)
                .head(head())
                .sheet()
                .registerWriteHandler(new AbstractCellStyleStrategy() {
                    CellStyle cellStyle;
                    @Override
                    protected void initCellStyle(Workbook workbook) {
                        CellStyle cellStyle = workbook.createCellStyle();
                        Font font = workbook.createFont();
                        font.setFontName("SansSerif");
                        cellStyle.setFont(font);
                        this.cellStyle = cellStyle;
                    }

                    @Override
                    protected void setHeadCellStyle(Cell cell, Head head, Integer relativeRowIndex) {
                        cell.setCellStyle(cellStyle);
                    }

                    @Override
                    protected void setContentCellStyle(Cell cell, Head head, Integer relativeRowIndex) {
                        cell.setCellStyle(cellStyle);
                    }
                })
                .doWrite(Collections.emptyList());

    }
    private static List<List<String>> head() {
        List<List<String>> head = new ArrayList<>();
        ArrayList<String> head1 = new ArrayList<>();
        head1.add("餐费全口径统计表");
        head1.add("单位类别");
        head.add(head1);

        ArrayList<String> head2 = new ArrayList<>();
        head2.add("餐费全口径统计表");
        head2.add("单位名称");
        head.add(head2);

        ArrayList<String> head3 = new ArrayList<>();
        head3.add("餐费全口径统计表");
        head3.add("早餐");
        head3.add("人次");
        head.add(head3);

        ArrayList<String> head4 = new ArrayList<>();
        head4.add("餐费全口径统计表");
        head4.add("早餐");
        head4.add("金额");
        head.add(head4);
        ArrayList<String> head5 = new ArrayList<>();
        head5.add("餐费全口径统计表");
        head5.add("小卖部");
        head.add(head5);
        return head;
    }


}
